#!/usr/bin/python
import rospy
from std_msgs.msg import String
import cv2
import detect
cap=cv2.VideoCapture(2)
a=detect.detectapi(weights='/home/fwy/桌面/yolo_test/yolo_ros/src/yolov5/scripts/runs/train/yolov5s/weights/Maturity.pt')
rospy.init_node("test")
pub = rospy.Publisher("/yolo_msg",String,queue_size=10)
msg = String()
while True:

    rec,img = cap.read()

    result,names =a.detect([img])
    img=result[0][0] #第一张图片的处理结果图片
    for cls,(x1,y1,x2,y2),conf in result[0][1]: #第一张图片的处理结果标签。
        print(names[cls],x1,y1,x2,y2,conf)
        msg.data = names[cls]
        pub.publish(msg)
    cv2.imshow("vedio",img)

    if cv2.waitKey(1)==ord('q'):
        break
